#include <stdio.h>
#include <unistd.h>

#include "ohos_init.h"
#include "cmsis_os2.h"
#include "st7735s.h"

#include "hi_time.h"
#include <time.h>
unsigned short color1[130*162];
unsigned short color2[130*162];
static void Smart_TimeKeeper_Task(void *arg)
{
    (void)arg;


    lcdInit();
    lcdClear(0xFFFF);
    for(int i = 0 ;i < 130*162 ; i++)
    {
        color1[i] = BRED;
        color2[i] = GREEN;
    }
    hi_u32 new = 0;
    hi_u32 old = 0;
    while (1)
    {
        old = hi_get_milli_seconds();
        LCD_Fill(0,0,130,162,color1);
        
        //lcdClear(YELLOW);
        // lcdClear(BRRED);
        // lcdClear(DARKBLUE);
        // lcdClear(YELLOW);
        // lcdClear(BRRED);
        // lcdClear(DARKBLUE);
        // lcdClear(YELLOW);
        // lcdClear(BRRED);
        // lcdClear(DARKBLUE);
        // lcdClear(BRRED);
        new = hi_get_milli_seconds();
        //printf("old : %lu ms , new : % lu ms\n",old,new);
        hi_u32 duration = (new - old);
        float fps = 1000.0f / duration;
        printf("Full screen refresh time: %lu ms, FPS: %.2f\n", duration, fps);
        usleep(150000);
        LCD_Fill(0,0,130,162,color2);
        usleep(100000);
    }
}

static void Smart_TimeKeeper_Entry(void)
{
    osThreadAttr_t attr;

    attr.name = "Smart_TimeKeeper_Task";
    attr.attr_bits = 0U;
    attr.cb_mem = NULL;
    attr.cb_size = 0U;
    attr.stack_mem = NULL;
    attr.stack_size = 1024 * 20;
    attr.priority = osPriorityNormal;

    if (osThreadNew(Smart_TimeKeeper_Task, NULL, &attr) == NULL)
    {
        printf("[Smart_TimeKeeper_Task] Falied to create Smart_TimeKeeper_Task!\n");
    }
}

SYS_RUN(Smart_TimeKeeper_Entry);
